package com.example.fuzhuang.controller;

import com.example.fuzhuang.dto.Type;
import com.example.fuzhuang.req.TypeReq;
import com.example.fuzhuang.resp.CommonResp;
import com.example.fuzhuang.resp.TypeResp;
import com.example.fuzhuang.services.TypeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


@RestController //这是返回接口
@RequestMapping("/type")
public class TypeController {

    private static final Logger LOG = LoggerFactory.getLogger(TypeController.class);

    @Resource
    private TypeService typeService;

    @PostMapping("/save")
    public CommonResp<TypeResp> save(@Valid @RequestBody TypeReq req){
        CommonResp<TypeResp> resp= new CommonResp<>();
        TypeResp typeResp = typeService.save(req);
        resp.setData(typeResp);
        return resp;
    }

    @GetMapping("/all")
    public CommonResp<List<TypeResp>> all(@Valid TypeReq req){
        CommonResp<List<TypeResp>> resp= new CommonResp<>();
        List<TypeResp> res = typeService.all(req);
        resp.setData(res);
        return  resp;
    }

    @GetMapping("/delete")
    public CommonResp delete(@Valid TypeReq req){
        CommonResp resp= new CommonResp<>();
        typeService.delete(req);
        return  resp;
    }

    @PostMapping("/batchUpdate")
    public CommonResp<List<Type>> batchUpdate(@Valid @RequestBody List<TypeReq> req){
        CommonResp<List<Type>> resp= new CommonResp<>();
        List<Type> res = typeService.batchUpdate(req);
        resp.setData(res);
        return resp;
    }
}

